import { Chart, Tooltip, Interval } from 'bizcharts';
// 属性类型
type PropField = {
  datas: Record<string, any>;
  xCol: string;
  yCol: string;
  height: number;
};
const ColumnChart: React.FC<PropField> = (props) => {
  const { datas, xCol, yCol, height } = props;
  let minVal = 6000000;
  for (let i = 0; i < datas.length; i++) {
    if (datas[i][yCol] && datas[i][yCol] < minVal) {
      minVal = datas[i][yCol];
    }
  }
  if (minVal > 0) {
    minVal = minVal - minVal * 0.01;
  }
  const scale = {
    [yCol]: { min: minVal },
  };
  return (
    <Chart height={height} padding="auto" data={datas} scale={scale} autoFit>
      <Interval position={`${xCol}*${yCol}`} />
      <Tooltip shared />
    </Chart>
  );
};
export default ColumnChart;
